<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">
			<title>海科新源业务协同管理平台(CMP)</title>
			<link rel="alternate icon" type="image/png" href="<%=path%>/resourse/AmazeUI-2.7.2assets/i/favicon.png">
			<link rel="stylesheet" href="<%=path%>/resourse/AmazeUI-2.7.2/assets/css/amazeui.min.css" />
			<link rel="stylesheet" href="<%=path%>/resourse/AmazeUI-2.7.2/assets/css/admin.css">
			<style>
				body {
					background: linear-gradient(to right, rgba(255, 0, 0, 0),
							rgba(229, 241, 243, 1));
				}

				.header {
					text-align: center;
				}

				.header h1 {
					font-size: 200%;
					color: #333;
					margin-top: 30px;
				}

				.header p {
					font-size: 14px;
				}
			</style>
		</head>

		<body>
			<div class="header">
				<div class="am-g">
					<h1>海科新源业务协同管理平台(CMP)</h1>
					<!-- 			<p> -->
					<!-- 				Integrated Development Environment<br />代码编辑，代码生成，界面设计，调试，编译 -->
					<!-- 			</p> -->
				</div>
				<hr />
			</div>
			<div class="am-g">
				<div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
					<!-- 			<h3>登录</h3> -->
					<!-- 			<hr> -->
					<!-- 			<div class="am-btn-group"> -->
					<!-- 				<a href="#" class="am-btn am-btn-secondary am-btn-sm"><i -->
					<!-- 					class="am-icon-github am-icon-sm"></i> Github</a> <a href="#" -->
					<!-- 					class="am-btn am-btn-success am-btn-sm"><i -->
					<!-- 					class="am-icon-google-plus-square am-icon-sm"></i> Google+</a> <a -->
					<!-- 					href="#" class="am-btn am-btn-primary am-btn-sm"><i -->
					<!-- 					class="am-icon-stack-overflow am-icon-sm"></i> stackOverflow</a> -->
					<!-- 			</div> -->
					<br> <br>

					<form method="post" class="am-form">
						<label for="email">登录名:</label> <input type="email" name="loginName" id="loginName" value="">
						<br> <label for="password">密码:</label>
						<input type="password" name="password" id="password" value="">
						<!-- 				<br> <label for="remember-me"> <input id="remember-me" -->
						<!-- 					type="checkbox"> 记住密码 -->
						<!-- 				</label> <br /> -->
						<br />
						<div class="am-cf">
							<input type="button" value="登录" onclick="login()"
								class="am-btn am-btn-default am-btn-sm am-fr"> <a href="supply/login" target="_blank"
								class="easyui-linkbutton">业务伙伴登录入口</a>

							<!-- 						 <input -->
							<!-- 						type="submit" name="" value="登 录" -->
							<!-- 						class="am-btn am-btn-primary am-btn-sm am-fl"> -->
							<!--         <input type="submit" name="" value="忘记密码 ^_^? " class="am-btn am-btn-default am-btn-sm am-fr"> -->
						</div>
					</form>
					<hr>
					<!-- 			<p>山东海科新源材料科技股份有限公司.</p> -->
				</div>
			</div>

			<script>
				function loginForSupply() {
					window.location.href = "<%=basePath%>supply/login";
				}

				function login() {
					var name = $('#loginName').val();
					var pwd = $('#password').val();
					console.log('name:' + name + 'pwd:' + pwd);
					$.ajax({
						type: "post",
						url: "api/sys/loginin",
						dataType: "json",
						data: {
							loginName: name,
							pwd: pwd
						},
						//contentType : "application/json",
						success: function (data) {
							if (data.code == 60200) {
								localStorage.setItem("token", data.data.tokenString);
								localStorage.setItem("sysUser", JSON.stringify(data.data.sysUser));
								var map = jsonToMap(data.data.btnPermission);
								localStorage.setItem("PERMISSIONS",  JSON.stringify(Object.fromEntries(map)));
								window.location.href = "<%=basePath%>sys/default";
							} else {
								alert('用户名或密码不正确');
							}
						},
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							alert(errorThrown);
						}
					});
				}

				function jsonToMap(array) {
					var map = new Map();
					for (var json of array) {
						console.log(json.moduleurl);
						map.set(json.moduleurl, json.PERMISSIONS);
					}
					return map;
				}

				//为button设置回车事件（百度搜索所得）
				//为keyListener方法注册按键事件
				document.onkeydown = keyListener;
				function keyListener(e) {
					// 当按下回车键，执行我们的代码
					if (e.keyCode == 13) {
						login();
					}
				}

			</script>

			<script src="<%=path%>/resourse/js/jquery.min.js"></script>
		</body>

		</html>